<template>
	<view class="wrap">
		<view class="tips">银行卡信息将设置在销售单表上，请核对清楚</view>
		<view class="cell">
			<view class="cell-item">
				<view class="cell-item_L">银行名称</view>
				<view class="cell-item_R" @click="showBankSelect = true">
					<!-- <input v-model="bankName" type="text" placeholder="请输入银行卡名称" placeholder-style="color: #ccc"> -->
					{{bankId ? bankName : '请选择银行卡'}}
				</view>
			</view>
			<view class="cell-item">
				<view class="cell-item_L">银行卡号</view>
				<view class="cell-item_R">
					<input v-model="bankNo" type="text" placeholder="请输入银行卡号码" placeholder-style="color: #ccc">
				</view>
			</view>
			<view class="cell-item">
				<view class="cell-item_L">户名</view>
				<view class="cell-item_R">
					<input v-model="realName" type="text" placeholder="请输入银行卡开户人姓名" placeholder-style="color: #ccc">
				</view>
			</view>
		</view>
		<view class="btn">
			<g-btn @click="onConfirmTap"></g-btn>
		</view>

		<u-select v-model="showBankSelect" :list="bankcarNameList" value-name="dictValue" label-name="dictLabel"
			@confirm="onBankSelectConfirm"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addBankCardFlag: false,
				bankcarList: [],
				bankcarNameList: [],
				bankName: '',
				bankId: '',
				bankNo: '',
				realName: '',
				showBankSelect: false,
			}
		},
		onLoad(options) {
			this.getBankcarNameList()
		},
		methods: {
			getBankcarNameList() {
				this.$g_api.bankcarBankNameList().then(({
					data
				}) => {
					this.bankcarNameList = data
				})
			},
			onBankSelectConfirm(res) {
				this.bankId = res[0].value
				this.bankName = res[0].label
			},
			async checkParams() {
				if (!this.bankId) return Promise.reject('请选择银行卡')
				if (!this.bankNo) return Promise.reject('请输入银行卡号')
				if (!this.realName) return Promise.reject('请输入姓名')
				return Promise.resolve({
					bankId: this.bankId,
					cardNumber: this.bankNo,
					name: this.realName,
					bankName: this.bankName
				})
			},
			async onConfirmTap() {
				try {
					let params = await this.checkParams()
					uni.$emit('updateBankCard', params)
					uni.navigateBack()
				} catch (e) {
					uni.showToast({
						title: e.toString(),
						icon: 'none'
					})
				}
			},

		}
	}
</script>

<style scoped lang="scss">
	.tips {
		padding-left: 30rpx;
		line-height: 80rpx;
		font-size: 26rpx;
		color: #666;

		&::before {
			content: '*';
			color: #ff7733;
		}
	}

	.cell {
		margin-bottom: 20rpx;
		padding: 0 30rpx;
		overflow: hidden;
		background-color: #fff;
	}

	.cell-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 100rpx;
		border-bottom: 1px solid #f2f2f2;

		&:last-child {
			border-bottom: 0;
		}
	}

	.cell-item_L {
		line-height: 98rpx;
		font-size: 30rpx;

		&::before {
			content: '*';
			color: #ff7733;
		}
	}

	.cell-item_R {
		text-align: right;
		font-size: 30rpx;

		input {
			width: 400rpx;
		}
	}

	.cell-btn_del {
		line-height: 80rpx;
		text-align: center;
		color: #FF4C4C;
	}

	.newCardBlock {
		margin: 50rpx auto 66rpx;
		width: 500rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 30rpx;
		color: $g-main-color;
		background: #FFFFFF;
		border-radius: 10rpx;
	}

	.btn {
		margin-top: 50rpx;
		// margin: 0 auto;
		// width: 690rpx;
		// height: 90rpx;
		// line-height: 90rpx;
		// text-align: center;
		// font-size: 32rpx;
		// color: #fff;
		// background: linear-gradient(90deg, #3377FF, #6699FF);
		// box-shadow: 0rpx 6rpx 14rpx 0rpx rgba(76, 136, 255, 0.5);
		// border-radius: 45rpx;
	}
</style>
